<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
jimport('joomla.application.component.model');

class ServersModelServer extends JModel
{
    /**
     * Constructor that retrieves the ID from the request
     */
    function __construct()
    {
        parent::__construct();

        $array = JRequest::getVar('cid', 0, '', 'array');
        $this->setId((int)$array[0]);
    }

    /**
     * Method to set identifier
     */
    function setId($id)
    {
        // Set id and wipe data
        $this->_id = $id;
        $this->_data = null;
    }


    function getUserList($id)
    {
        $query = "SELECT u.* FROM #__users as u, #__zakaz as z WHERE (z.idserver = " .
            (int)$id . ' ) and (z.iduser=u.id) ';

        $result = $this->_getList($query);
        return @$result;
    }

    /**
     * Method to get
     */
    function &getData()
    {
        // Load the data
        if (empty($this->_data)) {
            $query = ' SELECT * FROM #__server ' .
                '  WHERE id = ' . $this->_id;
            $this->_db->setQuery($query);
            $this->_data = $this->_db->loadObject();
        }
        if (!$this->_data) {
            $this->_data = new stdClass();
            $this->_data->id = 0;
            $this->_data->text = null;
            $this->_data->manufacturer = null;
            $this->_data->ram = null;
            $this->_data->chipset = null;
            $this->_data->published = null;
            $this->_data->ram = null;
            $this->_data->hdd = null;
            $this->_data->traphic = null;
            $this->_data->pricetr = 0;
            $this->_data->pricetrold = 0;
            $this->_data->priceinst = 0;
            $this->_data->ipaddr = null;
            $this->_data->commentt = null;
            $this->_data->photo_large = null;
            $this->_data->photo_small = null;
            $this->_data->typesrv = null;
            $this->_data->countzakaz = 0;
            $this->_data->indtypesrv = null;
        }

        return $this->_data;
    }

    /**
     * Method to store a record
     */
    function store()
    {
        $row =& $this->getTable();

        $data = JRequest::get('post');

        // Bind the form fields to the hello table
        if (!$row->bind($data)) {
            JError::raiseWarning(500, $row->getError());
            return false;
        }

        // Make sure the record is valid
        if (!$row->check()) {
            JError::raiseWarning(500, $row->getError());
            return false;
        }

        // Store table to the database
        if (!$row->store()) {
            JError::raiseWarning(500, $row->getError());
            return false;
        }

        return true;
    }

    /**
     * Method to delete record(s)
     */
    function delete()
    {
        $cids = JRequest::getVar('cid', array(0), 'post', 'array');

        $row =& $this->getTable();

        if (count($cids)) {
            foreach ($cids as $cid) {
                if (!$row->delete($cid)) {
                    JError::raiseWarning(500, $row->getError());
                    return false;
                }
            }
        }
        return true;
    }


}

?>
